<template>
  <a-input-search
    :placeholder="searchWord"
    style="width: 15rem"
    @search="onSearch"
    @focus="focus"
  />
</template>

<script>
export default {
  name: "Search",
  data() {
    return {
      searchWord: "搜索掘金",
    };
  },
  methods: {
    onSearch(val) {
      this.$router
        .push({ name: "search", query: { q: val } })
        .then(() => {
          this.$bus.$emit("getNewSeachContent");
        })
        .catch((err) => {
          this.$bus.$emit("getNewSeachContent"); // 防止在相同路径下报错
        });
    },
    focus() {
      this.searchWord = "文章/小册/标签/用户";
    },
  },
};
</script>
